﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Hosting;
using System.Web.Mvc;

namespace AcademicPlanner.Framework.Helpers
{
	/// <summary>
	/// UrlHelperExtensions provides static helper methods for
	/// creating urls to pages and resources of the application.
	/// The methods are extensions to the ASP.NET MVC <c>UrlHelper</c>.
	/// </summary>
	/// <version>1.0</version>
	/// <since>1.0</since>
	public static class UrlHelperExtensions
	{
		/// <summary>
		/// Gets the url to a css file based on the theme currently set
		/// in the session.
		/// </summary>
		/// <param name="urler">The ASP.NET MVC <c>UrlHelper</c> being extended.</param>
		/// <param name="stylesheetName">The css file name.</param>
		/// <returns>The complete url to the css file.</returns>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public static string Css(this UrlHelper urler, string stylesheetName)
		{
			string rUrl = "";
			string vTheme = (string)SessionHelper.Get("Presentation.Theme");
			
			if (!string.IsNullOrEmpty(vTheme) 
				&& HostingEnvironment.VirtualPathProvider.FileExists("~/Content/Themes/" + 
						vTheme + "/CSS/" + stylesheetName + ".css"))
			{
				rUrl = "/Content/Themes/" + vTheme + "/CSS/" + stylesheetName + ".css";
			}
			else
			{
				rUrl = "/Content/CSS/" + stylesheetName + ".css";
			}

			return rUrl;
		}

		/// <summary>
		/// Gets the url to a js file.
		/// </summary>
		/// <param name="urler">The ASP.NET MVC <c>UrlHelper</c> being extended.</param>
		/// <param name="scriptName">The js file name.</param>
		/// <returns>The complete url to the js file.</returns>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public static string Js(this UrlHelper urler, string scriptName)
		{
			return "/Scripts/" + scriptName + ".js";
		}

	}
}
